<?php
class Nguyen_Controller_Plugin_Permission extends Zend_Controller_Plugin_Abstract
{
	public function preDispatch(Zend_Controller_Request_Abstract $request)
	{
		$auth = Zend_Auth::getInstance();
    	$infoUser = $auth->getIdentity();
    	if(!$auth->hasIdentity()){
    		if($request->getModuleName()=='administrator'){
	    		$request->setModuleName('front');
	    		$request->setActionName('login');
	    		$request->setControllerName('user');
    		}
    	}
    	if($request->getModuleName()=='front'){
    		$model = new Administrator_Model_System();
    		$siteinfo = $model->GetSiteInfo();
    		if($siteinfo['siteoffline'] == 2 && $infoUser->type != 1){//loi
    			if($request->getControllerName()!== 'user'){
	    			$request->setModuleName('front');
	    			$request->setActionName('websiteclose');
	    			$request->setControllerName('index');
    			}
    		}
    	}
	}
}